using UnityEngine;
using System.Collections;

[RequireComponent (typeof(Collider))]
public class ComponentCollidable : MonoBehaviour
{
	[SerializeField]
	protected int CollideDamage = 1;
	
	void OnCollisionEnter(Collision collision)
	{
		ContactPoint contact = collision.contacts[0];
		
		//if the colliding gameObject is of different types, reduce both's health.
		if (contact.otherCollider.gameObject.name !=this.gameObject.name)
		{
			ComponentHealth otherHealth = contact.otherCollider.gameObject.GetComponent<ComponentHealth>();
			if (otherHealth != null)
			{
				otherHealth.Modify(-CollideDamage);
			}
		}
	}
}
